
$(function(){
  getInfo();

})

function getInfo(){
  var thisUrl = window.location.href;
  var thisId= '',thisTimeStamp = '',thisNonceStr = '',thisSignature ='';
  $.ajax({
    type: "post",
    /*url: "http://192.168.20.183:8080/getWxtoken",*/
    /*url: "http://scgcapi.sctv.com:28081/getWxtoken",*/
    url: "http://scgcapi.sctv.com:28080/scgc/getWxtoken",
    dataType : 'json',
    data:{'thisUrl':thisUrl},
    success: function (msg) {
      thisId = msg.appid;
      thisTimeStamp = msg.timestamp;
      thisNonceStr = msg.noncestr;
      thisSignature = msg.signature;
      getConfig(thisId,thisTimeStamp,thisNonceStr,thisSignature);
      getConfig2(thisId,thisTimeStamp,thisNonceStr,thisSignature);
    },
    error: function (msg) {
      // window.location.href = "404.jsp";
    }
  });

}
function getConfig2(id,stamp,Str,ture){
  setShareInfo({
    title: document.title,
    summary:"直播盐都·视频新闻第一屏",
    pic:'http://192.168.81.70:8080/logo/pingchang_logo.png',
    url: window.location.href,
    WXconfig:{
      swapTitleInWX: false,
      appId: id,
      timestamp: stamp,
      nonceStr: Str,
      signature:ture
    }
  });
}


/*初始化配置*/
function getConfig(id,stamp,Str,ture){
  wx.config({
    debug: false,
    appId: id,
    timestamp: stamp,
    nonceStr: Str,
    signature: ture,
    jsApiList: [
      'checkJsApi',
      'onMenuShareTimeline',
      'onMenuShareAppMessage',
      'onMenuShareQQ',
      'onMenuShareQZone'
    ]
  });
}

wx.ready(function () {
  // 1 判断当前版本是否支持指定 JS 接口，支持批量判断
  wx.checkJsApi({
    jsApiList: ['onMenuShareTimeline','onMenuShareAppMessage','onMenuShareQQ','onMenuShareQZone'], // 需要检测的JS接口列表，所有JS接口列表见附录2,
    success: function(res) {

    }
  });
  /*分享到朋友圈*/
  wx.onMenuShareTimeline({
    title:document.title, // 分享标题
    link: window.location.href, // 分享链接
    imgUrl: 'http://192.168.81.70:8080/logo/pingchang_logo.png', // 分享图标
    trigger: function (res) {

    },
    success: function () {

    },
    cancel: function () {

    }
  });
  /*分享到朋友*/

  wx.onMenuShareAppMessage({
    title: document.title, // 分享标题
    desc: "直播盐都·视频新闻第一屏", // 分享描述
    link: window.location.href, // 分享链接
    imgUrl: 'http://192.168.81.70:8080/logo/pingchang_logo.png', // 分享图标
    type: '', // 分享类型,music、video或link，不填默认为link
    dataUrl: '', // 如果type是music或video，则要提供数据链接，默认为空
    success: function () {

    },
    cancel: function () {

    }
  });
  /*分享到QQ空间*/
  wx.onMenuShareQZone({
    title:document.title,  // 分享标题
    desc: "直播盐都·视频新闻第一屏", // 分享描述
    link: window.location.href, // 分享链接
    imgUrl: 'http://192.168.81.70:8080/logo/pingchang_logo.png', // 分享图标
    success: function () {
      // 用户确认分享后执行的回调函数
    },
    cancel: function () {
      // 用户取消分享后执行的回调函数
    }
  });
  /*分享到QQ*/
  wx.onMenuShareQQ({
    title: document.title, // 分享标题
    desc: "直播盐都·视频新闻第一屏", // 分享描述
    link: window.location.href, // 分享链接
    imgUrl: 'http://192.168.81.70:8080/logo/pingchang_logo.png', // 分享图标
    success: function () {
      // 用户确认分享后执行的回调函数
    },
    cancel: function () {
      // 用户取消分享后执行的回调函数
    }
  });
});
